-- die_clean_all
-- created by chendh
-- 死亡击杀所有怪物以及存在的建筑

return {
    apply = function(prop, baseValue)
        return baseValue + prop[3];
    end,

    -- 死亡触发
    trigger = function(who, prop, arg)
        if who.type ~= OBJECT_TYPE_MONSTER then
            return;
        end

        trace("die_kill_all", "kill all monsters");

        for pos = 1, GRID_SIZE do
            local grid = DungeonM.getGridByPos(pos);
            local monster = grid.monster;
            
            -- 击杀所有活着的怪物
            if grid:isOpened() and monster and not monster:isDead() then
                local hp = monster:getHp();
                monster:setRealHp(0);
                monster:die();

                -- 先初始化
                SkillM.initSequence(who, monster, 0);
                SkillM.getSequence(monster):die(who, monster, hp, 0);

            elseif BossTentM.isTentGrid(pos) then
                -- 清掉流浪者帐篷
                
                -- 把格子设置为失效
                grid:changeState(GRID_STATE_DISABLE);

                -- 抛出格子失效事件
                EventMgr.fire(event.MONSTER_BUILDING_DISABLE, {["pos"] = grid:getPos()});
            elseif grid.type == GRID_TYPE_BOSS_STONE then
                -- 清掉石柱
                grid:changeState(GRID_STATE_DISABLE);
                EventMgr.fire(event.UPDATE_STONE_STATUS, { ["pos"] = pos, ["status"] = STONE_STATE_DISABLE, });
            end
        end

        return true;
    end,

    record = function(target, prop, path)
        return false;
    end
};